package com.johnrambo.ktea.ktExtends

import android.content.Context
import android.content.SharedPreferences

class ShareUtils {
    val NAME: String = "config"

    //存储String类型参数
    // 键 值
    fun putString(mContext: Context, key: String, value: String) {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        sp.edit().putString(key, value).commit()
    }

    //读取String类型参数
    // 键 默认值
    fun getString(mContext: Context, key: String, defvalue: String): String {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        return sp.getString(key, defvalue)!!
    }

    //存储Int类型参数
    // 键 值
    fun putInt(mContext: Context, key: String, value: Int) {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        sp.edit().putInt(key, value).commit()
    }

    //读取Int类型参数
    // 键 默认值
    fun getInt(mContext: Context, key: String, defvalue: Int): Int {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        return sp.getInt(key, defvalue)!!
    }

    //存储Boolean类型参数
    // 键 值
    fun putBoolean(mContext: Context, key: String, value: Boolean) {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        sp.edit().putBoolean(key, value).commit()
    }

    //读取Boolean类型参数
    // 键 默认值
    fun getBoolean(mContext: Context, key: String, defvalue: Boolean): Boolean {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        return sp.getBoolean(key, defvalue)!!
    }
    //存储long类型参数
    // 键 值
    fun putLong(mContext: Context, key: String, value: Long) {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        sp.edit().putLong(key, value).commit()
    }

    //读取long类型参数
    // 键 默认值
    fun getLong(mContext: Context, key: String, defvalue: Long): Long {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        return sp.getLong(key, defvalue)!!
    }
    //删除  单个
    fun deleShare(mContext: Context, key: String) {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        sp.edit().remove(key).commit()
    }

    //删除  全部
    fun deleAll(mContext: Context) {
        val sp: SharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE)
        sp.edit().clear().commit()
    }
}